<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_friends_shop/model')->方法名();
*/
namespace jy_friends_shop;
defined('BY_JYA') or exit('error');
class model extends \plugin{
	function check_agent(){
		$agent=$this->pdo_get('member',array('mid'=>$_SESSION['uid']));
		if(!$agent || $agent['status']!=1){
			exi('','error','apply/');
		}
		return true;
	}
	function update_price($from_mid,$goodsid,$newprice){
		$agent_goods_list=$this->pdo_getall('goods',array('from_mid'=>$from_mid,'goodsid'=>$goodsid));
		if(!$agent_goods_list){
			return true;
		}
		foreach($agent_goods_list as $agent_goods){
			$price=$newprice+$agent_goods['addprice'];
			if($price!=$agent_goods['price']){
				//发生变化才更新！
				$this->pdo_update('goods',array('price'=>$price),array('id'=>$agent_goods['id']));
				$this->update_price($agent_goods['mid'],$goodsid,$price);
			}
			
		}
		
		return true;
	}
}
?>